//Point.cpp

#include "Point.h"

void Point::move(int incX, int incY)
{
	m_x = m_x + incX;
	m_y = m_y + incY;
}

void Point::draw(char ch) const
{
	if ((m_x >= 0 && m_x <= SCR_HOR - 1) && (m_y >=0 && m_y <= SCR_VER - 1))
	{
		gotoxy(m_x, m_y);
		cout << ch;
		cout.flush();
	}
}

void Point::draw(char ch, int incX, int incY) const
{
	if ((m_x + incX >= 0 && m_x + incX <= SCR_HOR - 1) && (m_y + incY >=0 && m_y + incY <= SCR_VER - 1))
	{
		gotoxy(m_x + incX, m_y + incY);
		cout << ch;
		cout.flush();
	}
}

void Point::fixNegativePoint()
{
	if (m_x < 0)
		m_x += SCR_HOR;
	if (m_y < 0)
		m_y += SCR_VER;
}

void Point::drawToBuffer(char ch, Screen& scr, bool isSplit) const
{
	int scrVerFix = SCR_VER - 1;
	int scrHorFix = SCR_HOR - 1;

	if (isSplit)
	{
		scr.set(m_x % scrHorFix, m_y % scrVerFix, ch);
	}
	else
		if ((m_x >= 0 && m_x <= SCR_HOR - 1) && (m_y >=0 && m_y <= SCR_VER - 1))
			scr.set(m_x, m_y, ch);
}

void Point::drawToBuffer(char ch, int incX, int incY, Screen& scr, bool isSplit) const
{
	int scrVerFix = SCR_VER - 1;
	int scrHorFix = SCR_HOR - 1;

	if (isSplit)
	{
		scr.set((m_x + incX) % scrHorFix, (m_y + incY) % scrVerFix, ch);
	}
	else
		if ((m_x + incX >= 0 && m_x + incX <= SCR_HOR - 1) && (m_y + incY >=0 && m_y + incY <= SCR_VER - 1))
			scr.set(m_x + incX, m_y + incY, ch);
}

// Receives another Point and calculates the distance between them + round down.
int Point::distanceToOtherPoint(const Point otherPoint) const
{
	float distanceX = (float)abs(otherPoint.getX() - this->getX());	//distance between the circle point-x to the checked point-x
	float distanceY = (float)abs(otherPoint.getY() - this->getY());	//distance between the circle point-y to the checked point-y

	return (int)sqrt(distanceX*distanceX +  distanceY*distanceY);	//by Pythagoras it checks if the distnace between the two points
}